package com.fzz.netty.study.ws.controller;

import com.fzz.netty.study.ws.global.ChannelSupervise;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fankai
 * @version 1.0
 * @classname WebsocketController
 * @description TODO
 * @date 2021/11/02 10:42
 **/
@RestController
@RequestMapping("ws")
public class WebsocketController {

    @GetMapping("send2User")
    public Object send2User(String userId,String msg){
        ChannelSupervise.send2User(new TextWebSocketFrame(msg),userId);
        return "success";
    }


    @GetMapping("send2Module")
    public Object send2Module(String module,String msg){
        ChannelSupervise.send2Module(new TextWebSocketFrame(msg),module);
        return "success";
    }

    @GetMapping("send2ModuleUser")
    public Object send2ModuleUser(String module, String userId,String msg){
        ChannelSupervise.send2ModuleUser(new TextWebSocketFrame(msg),module,userId);
        return "success";
    }

    @GetMapping("send2All")
    public Object send2All(String msg){
        ChannelSupervise.send2All(new TextWebSocketFrame(msg));
        return "success";
    }
}
